from module.static_module.parent.view import SubWindowView
from module.static_module.main_window.view import MainWindowView

from tools.view import *


class MachineLearningView(SubWindowView):
    def __init__(self, main_window_view: MainWindowView):
        super().__init__(main_window_view)
        self.class_name = Module.MachineLearning.value
        tk.Label(self.frame, text=self.class_name).pack()

    def create_layout_init(self):
        # 绘制标签、内容组件
        # 配置参数
        # 当前模型名
        now_model_name = self.main_window_view.master.file_manager.now_model_name

        data_name_ls = self.main_window_view.master.dynamic_module_model_dc[
            self.main_window_view.master.file_manager.now_dynamic_module].data_name_ls
        symbol_name_ls = self.main_window_view.master.dynamic_module_model_dc[
            self.main_window_view.master.file_manager.now_dynamic_module].symbol_name_ls
        target_name_ls = self.main_window_view.master.dynamic_module_model_dc[
            self.main_window_view.master.file_manager.now_dynamic_module].target_name_ls
        engine_class_ls = self.main_window_view.master.dynamic_module_model_dc[
            self.main_window_view.master.file_manager.now_dynamic_module].engine_class_ls
        result_folder_ls = self.main_window_view.master.dynamic_module_model_dc[
            self.main_window_view.master.file_manager.now_dynamic_module].result_folder_ls

        label_config = [
            [LabelMember.ModelName, WidgetCategory.Label, [now_model_name], [0]],
            [LabelMember.DataName, WidgetCategory.Combobox, data_name_ls, []],
            [LabelMember.SymbolName, WidgetCategory.Combobox, symbol_name_ls, []],
            [LabelMember.TargetName, WidgetCategory.Combobox, target_name_ls, []],
            [LabelMember.EngineClass, WidgetCategory.Combobox, engine_class_ls, [0]],
            [LabelMember.ResultFolder, WidgetCategory.Entry, result_folder_ls, [0]]
        ]

        button_config = [
            [ButtonMember.Run, WidgetCategory.Button, None]
        ]
        self.auto_layout = AutoLayout(self.frame, label_config, button_config)
        self.auto_layout.button_command(self)

        bind_change_behavior = [
            [LabelMember.DataName, self.on_data_name_change]
        ]
        self.auto_layout.label_command(bind_change_behavior)

    def on_data_name_change(self):
        # 由实体类加载相应属性
        self.main_window_view.master.dynamic_module_model_dc[
            self.main_window_view.master.file_manager.now_dynamic_module].on_data_name_change()

        symbol_name_ls = self.main_window_view.master.dynamic_module_model_dc[
            self.main_window_view.master.file_manager.now_dynamic_module].symbol_name_ls
        target_name_ls = self.main_window_view.master.dynamic_module_model_dc[
            self.main_window_view.master.file_manager.now_dynamic_module].target_name_ls

        label_config = [
            [LabelMember.SymbolName, WidgetCategory.Combobox, symbol_name_ls, [0]],
            [LabelMember.TargetName, WidgetCategory.Combobox, target_name_ls, [0]]
        ]

        self.auto_layout.update_label_layout(label_config)




